package com.gmail.dmitryustimov.ms.java7.visitor.mod_actionmap.example.example2;


public class CarElementPrintVisitor<T> extends CarElementVisitor<T> {

    public <S extends T> CarElementPrintVisitor() {
        addVisitAction((Class<S>)Wheel.class,  (VisitAction<S>)this.new PrintWheel());
        addVisitAction((Class<S>)Engine.class, (VisitAction<S>)this.new PrintEngine());
        addVisitAction((Class<S>)Body.class,   (VisitAction<S>)this.new PrintBody());
        addVisitAction((Class<S>)Car.class,    (VisitAction<S>)this.new PrintCar());
    }

    public class PrintWheel implements VisitAction<Wheel> {
        @Override
        public void visit(Wheel wheel) {
            System.out.println("Visiting " + wheel.getName() + " wheel");
        }
    }

    public class PrintEngine implements VisitAction<Engine> {
        @Override
        public void visit(Engine engine) {
            System.out.println("Visiting engine");
        }
    }

    public class PrintBody implements VisitAction<Body> {
        @Override
        public void visit(Body body) {
            System.out.println("Visiting body");
        }
    }

    public class PrintCar implements VisitAction<Car> {
        @Override
        public void visit(Car car) {
            visitCar(car, CarElementPrintVisitor.this);
            System.out.println("Visiting car");
        }
    }
}
